# Contributor: Bart Ribbers <bribbers@disroot.org>
# Contributor: Grant Miller <GrantM11235@gmail.com>
# Contributor: Antoine Fontaine <antoine.fontaine@epfl.ch>
# Maintainer: Antoine Fontaine <antoine.fontaine@epfl.ch>
pkgname=anbox
pkgver=0_git20200609
pkgrel=0
_commit="c898810050df67adccd64a84b2d763250a42e722"
_cpu_features_commit="b5c271c53759b2b15ff91df19bd0b32f2966e275"
pkgdesc="Android in a box"
url="https://github.com/anbox/anbox"
arch="x86_64 armv7 aarch64"
license="GPL-3.0-or-later"
subpackages="$pkgname-openrc"
install="$pkgname.post-install"
depends="
	dbus
	dbus-libs
	mesa-gles
	mesa-egl
	fuse3
	"
makedepends="
	mesa-dev
	python3
	cmake
	cmake-extras
	lxc-dev
	sdl2-dev
	sdl2_image-dev
	boost-dev
	dbus-dev
	libcap-dev
	libdwarf-dev
	protobuf-dev
	elogind-dev
	properties-cpp-dev
	libexecinfo-dev
	gtest-dev
	glm-dev
	"
source="
	$pkgname-$_commit.tar.gz::https://github.com/anbox/anbox/archive/$_commit.tar.gz
	cpu_features-$_cpu_features_commit.tar.gz::https://github.com/google/cpu_features/archive/$_cpu_features_commit.tar.gz
	anbox-container-manager.initd
	anbox.confd
	musl-fixes.patch
	python3.patch
	fix-gtest-use.patch
	give-more-time-to-start.patch
	anbox-launch.sh
	anbox.desktop
	"
builddir="$srcdir/$pkgname-$_commit"

prepare() {
	# the bundled cpu_features is outdated and breaks build on arm.
	rm -r external/cpu_features
	cp -r $srcdir/cpu_features-*/ external/cpu_features

	default_prepare

	mkdir -p "$builddir"/build
}

build() {
	cd "$builddir"/build
	cmake "$builddir" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DANBOX_VERSION=alpine-$pkgver-r$pkgrel \
		-DWerror=OFF

	make
}

check() {
	cd "$builddir"/build
	make test
}

package() {
	cd "$builddir"/build
	DESTDIR="$pkgdir" make install

	# CPU Feature install itself. That's bad.
	rm "$pkgdir"/usr/bin/list_cpu_features
	rm "$pkgdir"/usr/lib/backward/BackwardConfig.cmake
	rm -r "$pkgdir"/usr/lib/cmake/CpuFeatures
	rm -r "$pkgdir"/usr/include

	install -m755 -D "$srcdir"/anbox-container-manager.initd \
		"$pkgdir"/etc/init.d/anbox-container-manager
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
	install -m755 -D "$srcdir"/$pkgname-launch.sh \
		"$pkgdir"/usr/bin/$pkgname-launch

	install -m644 -D "$srcdir"/$pkgname.desktop \
		"$pkgdir"/usr/share/applications/$pkgname.desktop
	install -m644 -D "$builddir"/snap/gui/icon.png \
		"$pkgdir"/usr/share/icons/hicolor/512x512/anbox.png

	# this is a dependency of the init script
	install -m755 -D "$builddir"/scripts/anbox-bridge.sh \
		"$pkgdir"/usr/share/anbox/anbox-bridge.sh
	# this is for convinience, to allow someone to get root access
	install -m755 -D "$builddir"/scripts/anbox-shell.sh \
		"$pkgdir"/usr/share/anbox/anbox-shell.sh
}

sha512sums="72656fa51e112492f1fdde46e08025201e3435aa5d6c69fc0ab15aa674e979c2c5e9f280966fe2d533a09019d99139addff68e700d163baaa782943b186e32fb  anbox-c898810050df67adccd64a84b2d763250a42e722.tar.gz
c0ec9b603cec2cc9049923e15ef50c85806bc0a0ffe57b63348631061aeddb73c1eca910b25696cf5eac2606aec3f86db29e8a01e01cf438bfee86edfe909e4a  cpu_features-b5c271c53759b2b15ff91df19bd0b32f2966e275.tar.gz
959058eb1c1e3eb0d1593695ee57fbc0cc567f260235e81d7b56da62b0b80fca9112d5f16a1e1c5c0e6223c8a1899f97f906c7cc763dc015e094aacded818a2f  anbox-container-manager.initd
6a3bc88142c5287ec54d481a4788eceb7772d9974af950b5286ce63a49d05d9d49fce5ba1d02b4b1c9893896fd4ba218fd4d39b8e640bdd61ad196b5d5c9a021  anbox.confd
401669509e05eb586ad40fc9e8f4284b52183f06c60e87bf4e923be165a72f10263daf226db7fd610ef6ff25d09abd140ca2d59187e2d1b85a0bd6ae887dd944  musl-fixes.patch
1130520444223f14cb865916f16c460bb0627b72c1c0a7e73564f99ca86fe5f6bdb1669c6d690cc963ca01dba8f8aff0a2e91897aa5779fed4c423aba38fdac8  python3.patch
12723c70e09c14f5e36499545edd1ec2a613e1d2bdc2cf134e8ddd9cb2d91695c9a74efa4530dce129a74f4b345ef59dff74c6703ed789b994e66c7e2901f11f  fix-gtest-use.patch
0f6324231028d32467dc95d43ed4865c29fde3396524479f514533e079179b0b068f1b38cbdf227af13d64ab117a27f3b962d8a99f5ecacf3fff4302d3ffe702  give-more-time-to-start.patch
921d69e28a2f63a6eaccdfbd6f53173d2e0c59dd650dd83c0d8f816b5f23f1ba61abb393b0cf5e48d80ce363df4f3e609de34a4e5a73c2b520dba96b76eda0c9  anbox-launch.sh
3e458e6215ecf0ac94d749f4d78e464850dcf2cc2b616b2f7ddf26e9617d63a90bd0c8be59e4540141a813af4bad84d0f84874105f7ef9de8149666fc3828da7  anbox.desktop"
